package com.yami.shop.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.model.TakeStockProd;
import com.yami.shop.bean.vo.TakeStockProdVO;
import com.yami.shop.dao.TakeStockProdMapper;
import com.yami.shop.manager.impl.LangManager;
import com.yami.shop.service.TakeStockProdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 盘点商品
 *
 * @author Citrus
 * @date 2021-09-15 11:18:33
 */
@Service
public class TakeStockProdServiceImpl extends ServiceImpl<TakeStockProdMapper, TakeStockProd> implements TakeStockProdService {

    @Autowired
    private TakeStockProdMapper takeStockProdMapper;
    @Autowired
    private LangManager langManager;

    @Override
    public List<TakeStockProdVO> listShopProd(Long takeStockId) {
        List<TakeStockProdVO> takeStockProdList = takeStockProdMapper.listShopProd(takeStockId);
        langManager.getTakeStockProdVOLang(takeStockProdList);
        return takeStockProdList;
    }

    @Override
    public void deleteByProdId(Long prodId) {
        if (Objects.isNull(prodId)) {
            return;
        }
        takeStockProdMapper.deleteByProdId(prodId);
    }

    @Override
    public List<Long> listInventoryByProdId(Long prodId) {
        return takeStockProdMapper.listInventoryByProdId(prodId);
    }

    @Override
    public List<Long> listTakeStockIdBySkuIds(List<Long> skuIds) {
        if (CollUtil.isEmpty(skuIds)) {
            return new ArrayList<>();
        }
        return takeStockProdMapper.listTakeStockIdBySkuIds(skuIds);
    }

    @Override
    public void deleteByProdId(Long prodId, List<Long> skuIds) {
        if (Objects.isNull(prodId) && CollUtil.isEmpty(skuIds)) {
            return;
        }
        //删除对应的商品
        takeStockProdMapper.deleteBySkuIds(prodId, skuIds);
    }
}
